package com.ikangtai.shecare.curve;

import android.app.Activity;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.baseView.guide.ViewPagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class CurveHelpActivity extends Activity implements View.OnClickListener{

    private ImageView closeButton, leftBtn, rightBtn;
    private ViewPager vp;
    private ViewPagerAdapter vpAdapter;
    private List<View> views;
    private LayoutInflater inflater;

    private static final int[] pics = {R.drawable.curve_guide_1,
            R.drawable.curve_guide_2, R.drawable.curve_guide_3,
            R.drawable.curve_guide_4, R.drawable.curve_guide_5};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_curve_help);
        initView();
    }

    private void initView() {

        closeButton = (ImageView) findViewById(R.id.curve_close_icon);
        closeButton.setOnClickListener(this);
        leftBtn = (ImageView) findViewById(R.id.curve_help_left);
        leftBtn.setOnClickListener(this);
        leftBtn.setVisibility(View.INVISIBLE);
        rightBtn = (ImageView) findViewById(R.id.curve_help_right);
        rightBtn.setOnClickListener(this);
        inflater = LayoutInflater.from(this);
        views = new ArrayList<View>();
        for(int i = 0; i < pics.length; i++){
            View view = inflater.inflate(R.layout.curve_guid_layout1, null);
            ImageView imgae = (ImageView) view.findViewById(R.id.curve_guide_image);
            Glide.clear(imgae);
            Glide.with(this).load(pics[i]).into(imgae);
            views.add(view);
        }
        vp = (ViewPager) findViewById(R.id.curve_help_viewpager);
        //初始化Adapter
        vpAdapter = new ViewPagerAdapter(views);
        vp.setAdapter(vpAdapter);
        vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if(position == 0) leftBtn.setVisibility(View.INVISIBLE);
                else leftBtn.setVisibility(View.VISIBLE);

                if(position == pics.length - 1) rightBtn.setVisibility(View.INVISIBLE);
                else rightBtn.setVisibility(View.VISIBLE);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){
            case R.id.curve_close_icon:
                CurveHelpActivity.this.finish();
                break;
            case R.id.curve_help_left:
                vp.setCurrentItem(vp.getCurrentItem() - 1);
                vpAdapter.notifyDataSetChanged();
                break;
            case R.id.curve_help_right:
                vp.setCurrentItem(vp.getCurrentItem() + 1);
                vpAdapter.notifyDataSetChanged();
                break;
            default:return;
        }

    }
}
